const { sendServerGet } = require("../../request/common")

// pages/login/index.js
Page({
  data:{
    userName:"",
    password:"",
  },
  userNameInput:function(options){
    let value=options.detail
    this.setData({
      userName:value
    })
  },
  passInput:function(options){
    let value=options.detail
    this.setData({
      password:value
    })
  },
  onOkBtn(){
    let params={},send={}
    send.userName=this.data.userName;
    send.password=this.data.password;
    params.send=send;
    params.url="customer/login";
    console.log(params)
    sendServerGet(params,(commRes)=>{
      // console.log(commRes)
      if(commRes.code==100){
        wx.showToast({
          title: '登录成功！',
          icon:"success"
        })
        wx.setStorageSync('userInfo', commRes.extend.user);
        wx.setStorageSync('token', commRes.extend.user.token);
       wx.navigateBack({
         delta: 1,
       })
      }else{
        wx.showToast({
          title: '账号或者密码错误',
          icon:"none"
        })
      }
    })
  }
})